

#ifndef __EV_TIMER_H__
#define __EV_TIMER_H__

#include <functional>
#include "ev_base.h"
#include <event2/event.h>

class EvTimer {

public:
    EvTimer(uint32_t timout_ms = 1000);
    ~EvTimer();
    EvTimer(const EvTimer&) = delete;
    EvTimer& operator=(const EvTimer&) = delete;
    EvTimer(EvTimer&& other) noexcept;
    EvTimer& operator=(EvTimer&& other) noexcept;

public:
    int setCallBack(std::function<void()> cb);
    int setAutoDelete(bool auto_delete);
    int start(uint32_t time_ms);
    int start();
    int stop();

private:
    struct event *event_;
    struct timeval timeout_;
    std::function<void()> onTimeout_;
    bool auto_delete_;

private:
    static void event_timer_cb(evutil_socket_t fd, short event, void *arg);
};

#endif /* __EV_TIMER_H__ */
